package com.weavernorth.createDoc;

import java.io.IOException;
import java.io.Writer;
import java.util.Map;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;


/**
 * @Author: BruseeWang
 * @Date: 2020/11/25 20:06
 * @Description:
 */
public class ToCreateDoc {
    private Configuration configuration = null;

    public ToCreateDoc() {
        configuration = new Configuration();
        configuration.setDefaultEncoding("UTF-8");
    }

    public void createDoc(Writer out, Map<String, Object> dataMap, String ftlName) {
        configuration.setClassForTemplateLoading(getClass(), "/ftl");
        try {

            Template t = null;
            t = configuration.getTemplate(ftlName,"UTF-8");
            t.process(dataMap, out);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
